﻿<cms-page-header cms-parent-title="Directories"
                 cms-title="vm.pageDirectory.fullUrlPath">
    <cms-directory-path cms-directory="vm.pageDirectory"></cms-directory-path>
</cms-page-header>

<cms-form cms-name="mainForm"
          cms-edit-mode="vm.editMode"
          ng-submit="vm.save()"
          cms-loading="vm.formLoadState.isLoading">

    <!-- Default toolbar -->
    <cms-page-actions ng-show="!vm.editMode">

        <cms-button class="main-cta"
                    cms-text="Edit"
                    ng-if="vm.canUpdate && vm.pageDirectory.depth !== 0"
                    ng-click="vm.edit()"
                    ng-disabled="vm.globalLoadState.isLoading"></cms-button>

        <cms-button cms-text="Change Url"
                    ng-if="vm.canUpdateUrl && vm.pageDirectory.depth !== 0"
                    ng-click="vm.changeUrl()"
                    ng-disabled="vm.editMode || vm.globalLoadState.isLoading"></cms-button>

        <cms-button cms-text="Access  Control"
                    ng-if="::vm.accessRulesEnabled"
                    ng-click="vm.viewAccessRules()"
                    ng-disabled="vm.editMode || vm.globalLoadState.isLoading"></cms-button>
        
        <cms-button cms-text="Delete"
                    ng-if="vm.canDelete && vm.pageDirectory.depth !== 0"
                    ng-click="vm.deleteDirectory()"
                    ng-disabled="vm.globalLoadState.isLoading"></cms-button>

    </cms-page-actions>

    <!-- Edit toolbar -->
    <cms-page-actions ng-show="vm.editMode">

        <cms-button-submit cms-text="Save"
                           ng-disabled="vm.mainForm.$invalid || vm.globalLoadState.isLoading"
                           cms-loading="vm.saveLoadState.isLoading"></cms-button-submit>

        <cms-button cms-text="Cancel"
                    ng-click="vm.cancel()"
                    ng-disabled="vm.globalLoadState.isLoading"></cms-button>

    </cms-page-actions>

    <!-- Scrollable content area -->
    <cms-page-body cms-content-type="form">

        <cms-warning-message ng-show="vm.pageDirectory.depth === 0">
            The root directory cannot be modified.
        </cms-warning-message>

        <cms-form-status></cms-form-status>

        <!--MAIN-->
        <cms-form-section cms-title="Main">

            <cms-form-field-readonly cms-title="Url Path"
                                     cms-model="vm.pageDirectory.urlPath"
                                     cms-description="The url path segment for this directory e.g. 'example-directory'."
                                     required></cms-form-field-readonly>

            <cms-form-field-text cms-title="Name"
                                cms-model="vm.command.name"
                                cms-description="An optional descriptive identifier, only used for managing the directory."
                                maxlength="200"></cms-form-field-text>

            <cms-form-field-readonly cms-title="Parent Directory"
                                    cms-model="vm.parentPageDirectory.fullUrlPath"
                                    cms-description="The parent under which to create this new directory."
                                    ng-if="vm.pageDirectory.depth !== 0"
                                    required></cms-form-field-readonly>

            <cms-form-field-readonly cms-title="Full Path"
                                     cms-model="vm.pageDirectory.fullUrlPath"></cms-form-field-readonly>

            <cms-form-field-container cms-title="Pages">
                <a ng-href="pages#/?pageDirectoryId={{::vm.pageDirectory.pageDirectoryId}}">{{::vm.pageDirectory.numPages}}</a>
            </cms-form-field-container>

            <cms-form-field-readonly cms-title="Child Directories"
                                     cms-model="::vm.pageDirectory.childPageDirectories.length"></cms-form-section>

        <!--DIRECTORIES-->

        <cms-form-section cms-title="Child Directories">

            <cms-form-field-container>
                <cms-directory-grid cms-directories="vm.pageDirectory.childPageDirectories"
                                    cms-redirect="true"></cms-directory-grid>
            </cms-form-field-container>

        </cms-form-section>

        <!--AUDIT DATA-->

        <cms-form-section-audit-data cms-audit-data="vm.pageDirectory.auditData"></cms-form-section-audit-data>

    </cms-page-body>

</cms-form>